package com.ibeetl.admin.core.service;


import com.ibeetl.admin.core.dao.CoreConfigDao;
import com.ibeetl.admin.core.entity.CoreConfig;
import com.ibeetl.admin.core.util.PlatformException;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 配置表 Service
 */

@Service
@Transactional
public class CoreConfigService extends CoreBaseService<CoreConfig>{

    @Autowired private CoreConfigDao coreConfigDao;

    public PageQuery<CoreConfig>queryByCondition(PageQuery query){
        PageQuery ret =  coreConfigDao.queryByCondition(query);
        queryListAfter(ret.getList());
        return ret;
    }

    public void batchDelCoreConfig(List<Long> ids){
        try {
            coreConfigDao.batchDelCoreConfigByIds(ids);
        } catch (Exception e) {
            throw new PlatformException("批量删除配置表失败", e);
        }
    }
    @Cacheable(value = CorePlatformService.CONFIG_TITLE_CACHE)
    public CoreConfig getConfigByTitle(String title) {
    	return this.coreConfigDao.getConfigByTitle(title);
    }

    @Override
    @CacheEvict(cacheNames = {CorePlatformService.CONFIG_TITLE_CACHE,CorePlatformService.COREFILE_CACHE_BATCHID}, allEntries = true)
    public int upsert(CoreConfig model) {
        return super.upsert(model);
    }
}